package com.ruoyi.launch.util;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.ruoyi.common.core.utils.uuid.UUID;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author :李金帅
 * @since 2024-11-27 Wednesday 19:57:07
 */

public class UpdateUtil {
    private static final String ALI_DOMAIN= "http://jiyun-ljs.oss-cn-beijing.aliyuncs.com/";
    public static String uploadImage(MultipartFile file) throws IOException {
        //生成文件名
        String orginalFileName=file.getOriginalFilename();//原来的图片名
        String ext="."+ FilenameUtils.getExtension(orginalFileName);
        String uuid = UUID.randomUUID().toString().replace("-", "");
        String fileName=uuid+ext;
        //地域节点
        String endpoint="http://oss-cn-beijing.aliyuncs.com";
        String accessKeyId="LTAI5tC4Pcbx2RK95kuSc8Jq";
        String accessKeySecret="RnwXgM3SOYAopgHs8PhLXY6v512ksH";
        //OSS客服端对象
        OSS ossClient=new OSSClientBuilder().build(endpoint,accessKeyId,accessKeySecret);
        ossClient.putObject("jiyun-ljs",fileName,file.getInputStream());
        ossClient.shutdown();
        return ALI_DOMAIN+fileName;
    }
}
